import * as types from './mutations_types.js'

let setDefaultState = (Val, defaultVal) => {
  return Val == undefined ? defaultVal : Val;
}

export default {
  [types.SET_USERTOKEN] (state, userToken) {
    state.userToken = setDefaultState(userToken, '');
  },
  [types.SET_SYSLANGUAGE] (state, active) {
    state.sysLanguage.active = setDefaultState(active, state.sysLanguage.active);
  },
  [types.SET_LANGOBJ] (state, langObj) {
    state.langObj = setDefaultState(langObj, state.langObj);
    window.localStorage.setItem('langObj', JSON.stringify(state.langObj));
  },
  [types.FULLSCREENTABLE_TOGGLE] (state, isFullScreenTable) {
    state.isFullScreenTable = setDefaultState(isFullScreenTable, !state.isFullScreenTable)
  },
  [types.ISMASK_TOGGLE] (state, isMask) {
    state.isMask = setDefaultState(isMask, !state.isMask)
  },
  [types.LOADING_TOGGLE] (state, isLoading) {
    state.isLoading = setDefaultState(isLoading, !state.isLoading)
  },
  [types.TOAST_TOGGLE] (state, isToasting) {
    state.isToasting = setDefaultState(isToasting, !state.isToasting)
  },
  [types.SET_TOAST] (state, toast) {
    state.toast.info = setDefaultState(toast.info, state.toast.info);
    state.toast.icon = setDefaultState(toast.icon, state.toast.icon);
    state.toast.time = setDefaultState(toast.time, state.toast.time);
  },
  [types.SIDEBAR_TOGGLE] (state, isHideSideBar) {
    state.isHideSideBar = setDefaultState(isHideSideBar, !state.isHideSideBar);
  },
  [types.SET_ALLMENU] (state, allMenu) {
    state.allMenu.list = setDefaultState(allMenu.list, state.allMenu.list);
    state.allMenu.active = setDefaultState(allMenu.active, state.allMenu.active);
  },
  [types.SET_SIDEMENULIST] (state, sideMenu) {
    state.sideMenu.list = setDefaultState(sideMenu.list, state.sideMenu.list);
    state.sideMenu.firstIndex = setDefaultState(sideMenu.firstIndex, state.sideMenu.firstIndex);
  },
  [types.SET_TABLIST] (state, tab) {
    state.tab.list = setDefaultState(tab.list, state.tab.list);
    state.tab.active = setDefaultState(tab.active, state.tab.active);
  },
  [types.SET_SYNCHRONIZEMENU] (state, isSynchronize) {
    state.tab.isSynchronize = setDefaultState(isSynchronize, !state.tab.isSynchronize);
  },
  [types.SET_MODAL] (state, modal) {
    state.modal.active = setDefaultState(modal.active, state.modal.active);
    state.modal.deactive = setDefaultState(modal.deactive, state.modal.deactive);
  },
  [types.DIALOG_TOGGLE] (state, isDialog) {
    state.dialog.isDialog = setDefaultState(isDialog, !state.dialog.isDialog);
  },
  [types.SET_DIALOG] (state, dialog) {
    state.dialog.title = setDefaultState(dialog.title, state.dialog.title);
    state.dialog.contents = setDefaultState(dialog.contents, state.dialog.contents);
    state.dialog.btnGroup = setDefaultState(dialog.btnGroup, state.dialog.btnGroup);
    state.dialog.confirmCallback = setDefaultState(dialog.confirmCallback, state.dialog.confirmCallback);
    state.dialog.cancelCallback = setDefaultState(dialog.cancelCallback, state.dialog.cancelCallback);
  },
  [types.SET_ISSYNCUSERSETTING] (state, isSyncUserSetting) {
    state.isSyncUserSetting = setDefaultState(isSyncUserSetting, !state.isSyncUserSetting);
  }
}
